from rest_framework import serializers

from recognition.models import CodeWhiteList


class BaseModelSerializer(serializers.ModelSerializer):
    created_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', read_only=True)

    class Meta:
        abstract = True


class CodeWhiteListCreate(BaseModelSerializer):
    class Meta:
        model = CodeWhiteList
        fields = '__all__'


class CodeWhiteListUpdate(serializers.ModelSerializer):
    class Meta:
        model = CodeWhiteList
        fields = '__all__'


class CodeWhiteListList(BaseModelSerializer):
    block_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S', read_only=True)

    class Meta:
        model = CodeWhiteList
        fields = '__all__'


class CodeWhiteListRetrieve(BaseModelSerializer):
    class Meta:
        model = CodeWhiteList
        fields = '__all__'


CODE_WHITE_LIST_SERIALIZERS_DICT = {
    'list': CodeWhiteListList,
    'create': CodeWhiteListCreate,
    'update': CodeWhiteListUpdate,
    'retrieve': CodeWhiteListRetrieve,
    'partial_update': CodeWhiteListUpdate
}
